import time

# 定义装饰器用于记录交易日志
def C(func):
    def wrapper(self, *args, **kwargs):
        result = func(self, *args, **kwargs)
        # 记录交易前余额
        prev_balance = self.c
        # 获取交易金额和类型
        amount = args[0] if args else 0
        transaction_type = 'a' if func.__name__ == 'A' else 'b'
        # 记录日志信息
        log_entry = {
            'time': time.strftime('%Y-%m-%d %H:%M:%S'),
            'transaction_type': transaction_type,
            'amount': amount,
            'prev_balance': prev_balance,
            'new_balance': self.c
        }
        self.d.append(log_entry)
        return result
    return wrapper

class BankAccount:
    # 初始化银行账户
    def __init__(self, a, b):
        self.a = a
        self.b = b
        self.c = 0.0
        self.d = []

    # 存款方法
    @C
    def A(self, a):
        if a > 0:
            self.c += a
            print(f"Deposited ${a:.2f}")
        else:
            print("Deposit amount must be positive.")

    # 取款方法
    @C
    def B(self, a):
        if a > 0:
            if a <= self.c:
                self.c -= a
                print(f"Withdrew ${a:.2f}")
            else:
                print("Insufficient funds.")
        else:
            print("Withdrawal amount must be positive.")

    # 查看余额方法
    def e(self):
        print(f"Current balance: ${self.c:.2f}")
        return self.c

    # 查看交易历史方法
    def f(self):
        if self.d:
            print("Transaction History:")
            for transaction in self.d:
                print(f"Time: {transaction['time']}")
                print(f"Type: {transaction['transaction_type']}")
                print(f"Amount: ${transaction['amount']:.2f}")
                print(f"Previous Balance: ${transaction['prev_balance']:.2f}")
                print(f"New Balance: ${transaction['new_balance']:.2f}")
                print("--------------------")
        else:
            print("No transactions yet.")

# 示例用法
if __name__ == "__main__":
    # 创建银行账户
    g = BankAccount("123456789", "John Doe")

    # 存款
    g.A(1000)
    g.A(500)

    # 取款
    g.B(300)

    # 查看余额
    g.e()

    # 查看交易历史
    g.f()